<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/26
 * Time: 14:14
 */

namespace App\Winged\Common\Controllers;


use App\Winged\Auth\Api\User;
use App\Winged\Components\Content;
use Illuminate\Http\Request;

class DepartmentController extends BaseController
{
    public function index(Request $request)
    {
        $page = $request->input('page_index','0');
        $size = $request->input('page_size','15');
        $parent_id = $request->input('parent_id','0');
        $department = User::getDepartmentList(['data' => json_encode(['user_id' => strval(user_id()) , 'parent_id' => $parent_id,'page_index' => $page,'page_size' => $size])]);
        if($request->wantsJson()){
            return response()->json($department);
        }
        return $this->Content(function(Content $content) use($department) {
            $view = view('winged.common::department.index',compact('department'));
            $content->body($view);
        });
    }
}